package cn.bdqn.veh.controller;

import cn.bdqn.model.PageBean;
import cn.bdqn.veh.model.Vehicle;
import cn.bdqn.veh.service.VehicleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author gurilla
 * @create 2019-08-20 14:10
 */
@Controller
@RequestMapping("/veh/vehicle")
public class VehicleController {
    @Resource
    private VehicleService vehicleService;

    @RequiresPermissions("veh:vehicle:page")
    @GetMapping
    public String topage(){
        return "/veh/vehicle";
    }

    @RequiresPermissions("veh:vehicle:list")
    @PostMapping("list")
    @ResponseBody
    public Object list(PageBean pageBean, String cidcard, String phone, String idcard, String cname, String lname){
        return vehicleService.list(pageBean, cidcard, phone, idcard, cname, lname);
    }

    @RequiresPermissions("veh:vehicle:save")
    @PostMapping("save")
    @ResponseBody
    public Object save(Vehicle vehicle){
        return vehicleService.save(vehicle);
    }

    @RequiresPermissions("veh:vehicle:delete")
    @PostMapping("delete")
    @ResponseBody
    public Object delete(Integer id){
        return vehicleService.delete(id);
    }

    @GetMapping("getAllColor")
    @ResponseBody
    public Object getAllColor(){
        return vehicleService.getAllColor().getData();
    }

    @GetMapping("getAllTruckType")
    @ResponseBody
    public Object getAllTruckType(){
        return vehicleService.getAllTruckType().getData();
    }

    @GetMapping("getAllLeader")
    @ResponseBody
    public Object getAllLeader(){
        return vehicleService.getAllLeader().getData();
    }

    @RequiresPermissions("veh:vehicle:auth")
    @PostMapping("auth")
    @ResponseBody
    public Object auth(Integer id){
        return vehicleService.auth(id);
    }
}
